<?php

namespace addons\config\user\controller;

class TopUp extends \web\user\controller\AddonUserBase{
    
    public function index(){
        return $this->fetch();
    }
    
    public function loadList(){
        $filter = ' 1 = 1 ';
        $m = new \addons\config\model\TopUp();
        $total = $m->getTotal($filter);
        $rows = $m->getDataList($this->getPageIndex(), $this->getPageSize(), $filter, '', 'update_time desc');
        return $this->toDataGrid($total, $rows);
    }
    
    public function loadData(){
        $id = $this->_get('id');
        $m = new \addons\config\model\TopUp();
        $data = $m->getDetail($id);
        return $data;
    }
    
    public function edit(){
        if (IS_POST) {
            $data['id'] = $this->_post('id');
            $data['address'] = $this->_post('address');
            $data['images'] = $this->_post('images');
            $data['content'] = $this->_post('content');
            $data['background_img'] = $this->_post('background_img');
            $data['update_time'] = NOW_DATETIME;
            $m = new \addons\config\model\TopUp();
            try {
               $ret = $m->save($data);
               if(!$ret){
                   return $this->failData('修改失败');
               }

                //添加管理日志
                $this->addLog(self::LOG_EDIT, 'TopUp', $data, 0, '充值设置');
               return $this->successData();
                
            } catch (\Exception $ex) {
                return $this->failData($ex->getMessage());
            }
        } else {
            $id = $this->_get('id');
            $this->assign('id', $id);
            $this->setLoadDataAction('loadData');
            return $this->fetch();
        }
    }
    
}
